package com.zxd.dao;

import com.zxd.entity.RoleModule;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * RoleModuleDao
 * Created by 奕恒 on 2017/2/20 21:48.
 */
public interface RoleModuleDao extends JpaRepository<RoleModule, Integer>, JpaSpecificationExecutor<RoleModule> {

    @Query("select a from RoleModule a where a.role.id in (select b.role.id from RoleRelation b where b.master.id = ?1) group by a.module.id")
    List<RoleModule> findListByMasterId(Integer masterId);

    @Query("select a from RoleModule a where a.role.id = ?1")
    List<RoleModule> findListByRoleId(Integer roleId);

    @Query("select a from RoleModule a where a.module.id = ?1")
    List<RoleModule> findListByModuleId(Integer moduleId);

    @Query("select a from RoleModule a where a.role.id = ?1 and a.module.id = ?2")
    List<RoleModule> findListByParams(Integer roleId,Integer moduleId);
}